package com.ctshk.sapp.order.goods.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.req.pay.NotifyConsumeReq;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.goods.req.OrderAddReq;
import com.ctshk.rpc.order.goods.req.OrderCommodityRefundReq;
import com.ctshk.rpc.order.goods.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * TODO
 *
 * @author 黄利斌
 * @date 2021/5/21 11:03 上午
 */
@Api(value = "中旅到家PC订单", tags = "中旅到家PC订单")
@RestController
@RequestMapping("/order/commodity/pay")
public class OrderCommodityPaymentController extends BaseController {

    @DubboReference
    private IOrderService orderService;

    @ApiOperation(value = "支付回调接口", notes = "支付回调接口")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "支付回调接口", operDesc = "支付回调接口")
    @PostMapping("/payCallback")
    public Result payCallback(@RequestBody NotifyConsumeReq req, @RequestParam Long shopId) throws Exception {
        TokenUser currentUser = getCurrentUser();
        if (null == currentUser) {
            return orderService.payCallback(req, null);
        } else {
            return orderService.payCallback(req, currentUser);
        }
    }

    @ApiOperation(value = "商品訂單支付", notes = "商品訂單支付")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "商品訂單支付", operDesc = "商品訂單支付")
    @GetMapping("/payment/{oderId}/{code}/{shopId}")
    public Result payment(@PathVariable("oderId") Long oderId, @PathVariable("code") Integer code, @PathVariable Long shopId) throws Exception {
//        return orderService.payPlatform(oderId, getCurrentUser(), code, shopId);
        return null;
    }

    @ApiOperation(value = "取消訂單", notes = "取消訂單")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "取消訂單", operDesc = "取消訂單")
    @PostMapping("/cancelOrder")
    public Result cancelOrder(@RequestBody @Valid List<OrderCommodityRefundReq> refundReqs) throws Exception {
        orderService.cancelAppOrder(refundReqs, getCurrentUser(getRequest()));
        return Result.success();
    }

    @ApiOperation(value = "新增門店訂單", notes = "新增門店訂單")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "新增門店訂單", operDesc = "新增門店訂單")
    @PostMapping("/addAppOrder")
    public Result addAppOrder(@RequestBody @Valid OrderAddReq obj) throws Exception {
//        orderService.addAppOrder(obj,getCurrentUser(getRequest()));
        return Result.success();
    }
}
